;(function () { 
    Element.extend({
        append: function (e) {
            this.appendChild(e);
            return this;
        },
        prepend: function (e) {
            var child = this.child()[0];
            child ? child.before(e) : this.append(e);
            return this;
        },
        after: function (e) {
            var n = this.next();
            n ? n.before(e) : this.parent().append(e);
            return this;
        },
        before: function (e) {
            this.parent().insertBefore(e, this);
            return this;
        },
        css: function (css, val) {
            if ($type(css) == 'object') for (var x in css) this.css(x, css[x]);
            else if (val != undefined) {
                this.setStyle(css, val);
                return this;
            } else return this.getStyle(css);
        },
        html: function (h) {
            return h ? this.setHTML(h) : this.innerHTML;
        },
        attr: function (a, b) {
            if (a) {
                if ($type(a) == 'object') {
                    for (var x in a) this.attr(x, a[x]);
                    return this;
                } else if (b != undefined) {
                    this.setProperty(a, b);
                    return this;
                } else return this.getProperty(a);
            } else return this.getProperties();
        },
        child: function (s) {
            return this.getChildren(s);
        },
        parent: function (s) {
            return this.parentNode;
        },
        next: function () {
            return this.getNext();
        },
        prev: function () {
            return this.getPrevious();
        },
        last: function () {
            return this.getLast();
        },
        first: function () {
            return this.getFirst();
        },
        find: function (e) {
            return this.getElements(e);
        },
        morph: function (o) {
            if (o) this.fx = new Fx.styles(o);
            else return this.fx;
            return this.fx;
        },
        offset: function (o) {
            return this.getCoordinates(o);
        },
        once: function(evt,func){
            var handle = function(){
                func.apply(this,arguments)
                this.removeEvent(evt,handle);
            }
            this.addEvent(evt,handle);
            return this;
        }
    });
    String.extend({
        toElements: function () {
            var obj = new Element('div');
            obj.html(this);
            return obj.child();
        },
        lTrim: function(){
            var sString = this.toString();
            while (sString.substring(0,1) == ' ')
                sString = sString.substring(1, sString.length);
            return sString;             
        },
        rTrim: function(){
            var sString = this.toString();
            while (sString.substring(sString.length-1, sString.length) == ' ')
                sString = sString.substring(0,sString.length-1);
            return sString;
        },
        trim: function(){
            return this.lTrim(this.rTrim());
        }
    });
    Object.extend({});
    Array.extend({
        swap: function (a, b) {
            var tmp = this[a];
            this[a] = this[b];
            this[b] = tmp;
        }
    });
    
})();